package ru.alexo.whiskey;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import ru.alexo.whiskey.events.ChordEvent;
import ru.alexo.whiskey.events.InstrumentChangeEvent;
import ru.alexo.whiskey.events.NoteEvent;
import ru.alexo.whiskey.events.TempoChangeEvent;
import ru.alexo.whiskey.util.Instrument;
import ru.alexo.whiskey.util.Notes;
import ru.alexo.whiskey.util.Octave;
import ru.alexo.whiskey.util.TonesHelper;

class WhiskeyRunner {

    public static void main(String[] args) {
	Midi midi = new Midi();
	MidiTrack track = midi.createTrack();

	track.addEvent(new TempoChangeEvent(120));
	track.addEvent(new InstrumentChangeEvent(Instrument.SteelStrGuitar));
	for (byte code = (byte) TonesHelper.getOctaveRootCode(Octave.OCTAVE_2); code < (byte) TonesHelper
		.getOctaveRootCode(Octave.OCTAVE_6); code++) {
	    track.addEvent(new NoteEvent((byte) 100, (byte) 16, code));
	}

	track.addEvent(new InstrumentChangeEvent(Instrument.ACOUSTIC_GRAND_PIANO));
	track.addEvent(new ChordEvent((byte) 100, (byte) 4, (byte) TonesHelper.getNoteCode(Octave.OCTAVE_5, Notes.C),
		(byte) TonesHelper.getNoteCode(Octave.OCTAVE_5, Notes.E), (byte) TonesHelper.getNoteCode(
			Octave.OCTAVE_5, Notes.G)));

	try {
	    File file = new File("C:\\miditest.mid");
	    file.mkdirs();
	    if (file.exists()) {
		file.delete();
	    }
	    file.createNewFile();
	    FileOutputStream fos = new FileOutputStream(file);
	    midi.serializeMidiContent(fos);
	    fos.close();
	} catch (IOException e) {
	    e.printStackTrace();
	}

    }

}
